<template>
	<view class="Recharge_content Transfer_content">
		<view class="kuang">
			<view class="title">
				<view class="inline-block left">
					<image src="../../static/image/left.png" mode="" @tap="back"></image>
				</view>
				<view class="inline-block titleText">
					币种管理
				</view>
			</view>
			
			<view class="manage">
				<view class="manage_title">选择在钱包中展示的币种</view>
				<view class="manage_item" v-for="(item,index) in assetsList" :key="index">
					<view class="detail_left">
						<image src="../../static/image/wallet_icon3.png"></image>
						<view class="left_right">
							<view>{{item.symbol}}</view>
						</view>
					</view>
					<view class="left_right">
						<!-- <switch :checked="item.isShow" @change="switch1Change($event,item.symbol)" class="switch" color="#00C9A7"/> -->
						<switch :checked="item.isShow" @change="switch1Change($event,index)" class="switch" color="#00C9A7"/>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import * as oex from 'oex-web3';
	import account from '../../common/account.js'
	import {myMixins} from '../../common/mixins.js'
	export default {
		mixins: [myMixins], // 使用mixin
		data() {
			
			return {
				balances:[],
				dataArr:[],
				isnoData:false,
				assetsList:[]
			}
		},
		onLoad() {
			// this.assetsList = uni.getStorageSync('assetsList');
			// console.log(this.assetsList)
			const _this = this;
			uni.showLoading();
			
			// this.assetsList = this.$store.getters.getAssetsList;
			// console.log(this.assetsList)
			
			this.getAccountExByName();
			
		},
		onUnload(){
			const _this = this;
			this.$store.commit('setAssetsList',this.assetsList);
			// uni.setStorage({
			// 	key:"assetsList",
			// 	data:_this.assetsList
			// })
		},
		methods: {
			async getAccountExByName(){
				//加载资产列表
				const _this = this;
				account.getAccount(this.account_info.accountName).then(res =>{
					if(res.data.result.balances.length > 0){
						_this.getInfoByAssetsID(res.data.result.balances);
					}else{
						_this.isnoData = true;
					}
					
					
				}).catch(error =>{
					console.log(error)
				})
			},
			
			getInfoByAssetsID(data){
				//查看币种
				const _this = this;
				const nodeInfo = uni.getStorageSync('nodeInfo');
				data.map(item =>{
					account.getCoin(nodeInfo,item.assetID).then(result =>{
						console.log(result)
						
						_this.dataArr.push(result.data.result) 
						uni.hideLoading()
					})
				})
				
			},
			back(){
				 this.$CommonJS.navigateBack('./wallet');
			},
			switch1Change: function (e,index) {
				this.assetsList[index].isShow = e.target.value;
			},
		}
	}
</script>

<style lang="stylus">
	@import "../../static/stylus/wallet/wallet.stylus"
</style>
